<template>
  <div class="app-container">
    <el-card shadow="never">
      <el-form :inline="true" :model="searchForm" class="search-form">
        <el-form-item label="项目名称">
          <el-input v-model.trim="searchForm.serverItem"></el-input>
        </el-form-item>
        <el-form-item label="报警时间">
          <el-date-picker v-model="searchForm.alterTime" type="date" range-separator="至" start-placeholder="开始日期"
            end-placeholder="结束日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="护士名称">
          <el-input v-model.trim="searchForm.nurseName"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleFilter" class="search-button">查询</el-button>
          <el-button @click="handleReset" class="search-button">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table ref="table" v-loading="listLoading" :data="list" element-loading-text="Loading" fit
        highlight-current-row>
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column align="center" type="index" label="序号" width="55">
        </el-table-column>
        <el-table-column label="订单编号" align="center" prop="orderNum">
        </el-table-column>
        <el-table-column label="就诊人" align="center" prop="patientName">
        </el-table-column>
        <el-table-column label="服务项目" align="center" prop="serverItem">
        </el-table-column>
        <el-table-column label="报警时间" align="center" prop="alterTime">
        </el-table-column>
        <el-table-column label="护士名称" align="center" prop="nurseName">
        </el-table-column>
        <el-table-column label="医院名称" align="center" prop="hospitalName">
        </el-table-column>
        <el-table-column label="处理人" align="center" prop="handlePeo">
        </el-table-column>
        <el-table-column align="center" label="操作" width="160">
          <template slot-scope="{row}">
            <el-button type="text" @click="showEdit(row)">处理</el-button>
            <el-button type="text" @click="showDetails(row)">查看</el-button>
            <el-button type="text" @click="delHandle(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="searchForm.pageIndex" :limit.sync="searchForm.pageSize"
        @pagination="getList" />
    </el-card>
    <el-dialog title="处理" :visible.sync="dialogVisible" width="40%">
      <el-form label-position="right" label-width="120px" ref="form" :model="form">
        <el-form-item label="处理结果">
          <el-input v-model.trim="form.proFirstClassName"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" class="btn-cancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="详情" :visible.sync="detailsDialog" width="40%">
      <el-form label-position="right" label-width="120px" ref="form" :model="form">
        <el-form-item label="订单编号">
          <div>{{form.orderNum}}</div>
        </el-form-item>
        <el-form-item label="服务项目">
          <div>{{form.serverItem}}</div>
        </el-form-item>
        <el-form-item label="就诊人">
          <div>{{form.patientName}}</div>
        </el-form-item>
        <el-form-item label="服务时间">
          <div>{{form.handleTime}}</div>
        </el-form-item>
        <el-form-item label="护士名称">
          <div>{{form.nurseName}}</div>
        </el-form-item>
        <el-form-item label="报警时间">
          <div>{{form.alterTime}}</div>
        </el-form-item>
        <el-form-item label="报警内容">
          <div>{{form.orderNum}}</div>
        </el-form-item>
        <el-form-item label="处理人">
          <div>{{form.handlePeo}}</div>
        </el-form-item>
        <el-form-item label="处理结果">
          <div>{{form.handleResult}}</div>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="detailsDialog = false" class="btn-cancel">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import * as pendingAlarm from '@/api/pendingAlarm'
import Pagination from '@/components/Pagination'
export default {
  components: { Pagination },
  data () {
    return {
      list: null,
      listLoading: true,
      searchForm: {
        pageIndex: 1,
        pageSize: 10,
        orderTime: [],
        serviceTime: [],
      },
      total: 0,
      dialogVisible: false,
      form: {},
      statusList: [{
        label: '待评估',
        value: '待评估'
      }, {
        label: '待派发',
        value: '待派发'
      }, {
        label: '待出发',
        value: '待出发'
      }, {
        label: '待服务',
        value: '待服务'
      }, {
        label: '服务中',
        value: '服务中'
      }, {
        label: '结束待确认',
        value: '结束待确认'
      }, {
        label: '待评价',
        value: '待评价'
      }, {
        label: '已完成',
        value: '已完成'
      }, {
        label: '已取消',
        value: '已取消'
      }, {
        label: '退款',
        value: '退款'
      },],
      detailsDialog: false
    }
  },
  created () {
    this.getList()
  },
  methods: {
    getList () {
      this.listLoading = true
      let param = Object.assign({}, this.searchForm)
      pendingAlarm.queryByPage(param).then(response => {
        this.list = response.data.rows
        this.total = response.data.total
        this.listLoading = false
      }).catch(error => {
        this.listLoading = false
        console.log(error)
      })
    },
    handleFilter () {
      this.searchForm.pageIndex = 1
      this.getList()
    },
    handleReset () {
      this.resetTemp();
      this.getList();
    },
    resetTemp () {
      this.searchForm = {
        pageIndex: 1,
        pageSize: 10,
      }
    },
    showAdd () {
      this.form = {}
      this.dialogVisible = true
    },
    showEdit (row) {
      this.form = Object.assign({}, row)
      delete this.form.createTime
      delete this.form.updateTime
      this.dialogVisible = true
    },
    submit () {
      this.editHandle()
    },
    creatHandle () {
      pendingAlarm.insert(this.form).then(response => {
        if (response.code == 200) {
          this.dialogVisible = false
          this.getList()
          this.$message.success('新增成功')
        }
      }).catch(error => {
        console.log(error)
      })
    },
    editHandle () {
      pendingAlarm.update(this.form).then(response => {
        if (response.code == 200) {
          this.dialogVisible = false
          this.getList()
          this.$message.success('修改成功')
        }
      }).catch(error => {
        console.log(error)
      })
    },
    delHandle (data) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const param = {
          uid: data.uid,
        }
        pendingAlarm.deleteById(param).then(result => {
          this.$message.success(result.msg)
          this.getList()
        }).catch(error => {
          this.loading = false
          console.log(error)
        })
      }).catch(() => {
        console.log('取消删除')
      });
    },
    showDetails (data) {
      this.form = Object.assign({}, data)
      this.detailsDialog = true
    },
    derive () {
      let url = process.env.VUE_APP_BASE_API + "/orderInfo/exportOrderInfo?"
      for (let key in this.searchForm) {
        if (this.searchForm[key]) {
          url = url + key + '=' + this.searchForm[key] + '&'
        }
      }
      //uidListStr
      let selection = this.$refs.table.selection
      let uidList = []
      if (selection.length > 0) {
        selection.forEach(item => {
          uidList.push(item.uid)
        })
        url = url + 'uidListStr=' + uidList.join(',')
      }
      // 创建一个a标签元素
      const downloadLink = document.createElement('a');

      // 设置a标签的href属性为下载链接
      downloadLink.href = url
      // 设置a标签的download属性为文件名
      downloadLink.download = 'file.pdf';
      // 将a标签添加到HTML文档中的某个元素中
      document.body.appendChild(downloadLink);
      // 触发a标签的点击事件，即模拟用户点击下载链接
      downloadLink.click();
      document.body.removeChild(downloadLink);
    },
  }
}
</script>
